package com.itheima.demo02.FileUpload;

import java.io.*;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) throws IOException {
        //获取读取本地文件
        FileInputStream fis = new FileInputStream("day10_IO\\1.jpg");
        //创建socket
        Socket socket = new Socket("127.0.0.1", 8888);
        //通过网络输出流传送本地文件数据
        OutputStream os = socket.getOutputStream();
        int len = 0;
        byte[] bytes = new byte[1024];
        while ((len = fis.read(bytes)) != -1) {
            os.write(bytes, 0, len);
        }
        socket.shutdownOutput();
        InputStream is = socket.getInputStream();
        while ((len = is.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, len));
        }
        fis.close();
        socket.close();
    }
}
